// bttView.cpp : implementation of the CbttView class
//

#include "stdafx.h"
#include "btt.h"

#include "bttDoc.h"
#include "bttView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CbttView

IMPLEMENT_DYNCREATE(CbttView, CFormView)

BEGIN_MESSAGE_MAP(CbttView, CFormView)
	ON_BN_CLICKED(IDC_BUTTON1, &CbttView::OnBnClickedButtonSolve3)
END_MESSAGE_MAP()

// CbttView construction/destruction

CbttView::CbttView()
	: CFormView(CbttView::IDD)
{
	// TODO: add construction code here

}

CbttView::~CbttView()
{
}

void CbttView::DoDataExchange(CDataExchange* pDX)
{
	CView::DoDataExchange(pDX);
	DDX_Check(pDX, IDC_CHECK11, ch11);
	DDX_Check(pDX, IDC_CHECK12, ch12);
	DDX_Check(pDX, IDC_CHECK13, ch13);
	DDX_Check(pDX, IDC_CHECK21, ch21);
	DDX_Check(pDX, IDC_CHECK22, ch22);
	DDX_Check(pDX, IDC_CHECK23, ch23);
	DDX_Check(pDX, IDC_CHECK31, ch31);
	DDX_Check(pDX, IDC_CHECK32, ch32);
	DDX_Check(pDX, IDC_CHECK33, ch33);
	DDX_Check(pDX, IDC_CHECKs11, chs11);
	DDX_Check(pDX, IDC_CHECKs12, chs12);
	DDX_Check(pDX, IDC_CHECKs13, chs13);
	DDX_Check(pDX, IDC_CHECKs21, chs21);
	DDX_Check(pDX, IDC_CHECKs22, chs22);
	DDX_Check(pDX, IDC_CHECKs23, chs23);
	DDX_Check(pDX, IDC_CHECKs31, chs31);
	DDX_Check(pDX, IDC_CHECKs32, chs32);
	DDX_Check(pDX, IDC_CHECKs33, chs33);
	DDX_Check(pDX, IDC_CHECKx11, chx11);
	DDX_Check(pDX, IDC_CHECKx12, chx12);
	DDX_Check(pDX, IDC_CHECKx13, chx13);
	DDX_Check(pDX, IDC_CHECKx21, chx21);
	DDX_Check(pDX, IDC_CHECKx22, chx22);
	DDX_Check(pDX, IDC_CHECKx23, chx23);
	DDX_Check(pDX, IDC_CHECKx31, chx31);
	DDX_Check(pDX, IDC_CHECKx32, chx32);
	DDX_Check(pDX, IDC_CHECKx33, chx33);
}

BOOL CbttView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

void CbttView::OnInitialUpdate()
{
	CView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();

}


// CbttView diagnostics

#ifdef _DEBUG
void CbttView::AssertValid() const
{
	CView::AssertValid();
}

void CbttView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CbttDoc* CbttView::GetDocument() const // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CbttDoc)));
	return (CbttDoc*)m_pDocument;
}
#endif //_DEBUG


// CbttView message handlers

void CbttView::OnBnClickedButtonSolve3()
{
	int matrix[3][3]= {0};
	int matrixP[3][3]= {0};
	int matrixF[3][3] = {0};


	UpdateData(true);

	matrix[0][0] = ch11;
	matrix[0][1] = ch12;
	matrix[0][2] = ch13;
	matrix[1][0] = ch21;
	matrix[1][1] = ch22;
	matrix[1][2] = ch23;
	matrix[2][0] = ch31;
	matrix[2][1] = ch32;
	matrix[2][2] = ch33;
	matrixP[0][0] = chs11;
	matrixP[0][1] = chs12;
	matrixP[0][2] = chs13;
	matrixP[1][0] = chs21;
	matrixP[1][1] = chs22;
	matrixP[1][2] = chs23;
	matrixP[2][0] = chs31;
	matrixP[2][1] = chs32;
	matrixP[2][2] = chs33;
	
	bool fail = true;

	for(int i = 0;i<2 && fail;i++)
	{
		for(int j = 0;j<2 && fail;j++)
		{
			for(int k = 0;k<2 && fail;k++)
			{
				if(i==1 && j==0 && k==1)
					fail = false;
				matrixF[0][0] = i;
				matrixF[0][1] = j;
				matrixF[0][2] = k;

				int m = 1;
				int n = 0 ;
				int r = 0;
		
				for(n= 0;n<3;n++)
				{
					r = 0;
					r += matrix[m-1][n];
					r += matrixF[m-1][n];
					if((n+1) < 3)
						r += matrixF[m-1][n+1];
					if((n-1) >= 0)
						r += matrixF[m-1][n-1];

					if( (r%2) == matrixP[m-1][n])
						matrixF[m][n] = 0;
					else
						matrixF[m][n] = 1;
				}
				m++;
				fail = false;

				for(n= 0;n<3;n++)
				{
					r = 0;
					r += matrix[m-1][n];
					r += matrixF[m-1][n];
					r += matrixF[m-2][n];
					if((n+1) < 3)
						r += matrixF[m-1][n+1];
					if((n-1) >= 0)
						r += matrixF[m-1][n-1];

					if( (r%2) == matrixP[m-1][n])
						matrixF[m][n] = 0;
					else
						matrixF[m][n] = 1;
					
					
					if((n-1) >= 0)
					{
						r = 0;
						r += matrixF[m][n-1];
						r += matrixF[m-1][n-1];
						r += matrixF[m][n];
						r += matrix[m][n-1];
						if((n-2) >= 0)
						{
							r += matrixF[m][n-2];
						}
						if( (r%2) != matrixP[m][n-1])
							fail = true;
					}
					if(n == 2)
					{
						r = 0;
						r += matrixF[m][n-1];
						r += matrixF[m-1][n];
						r += matrixF[m][n];
						r += matrix[m][n];
						if( (r%2) != matrixP[m][n])
							fail = true;
					}
				}
			}
		}
	}
	chx11 = matrixF[0][0];
	chx12 = matrixF[0][1];
	chx13 = matrixF[0][2];
	chx21 = matrixF[1][0];
	chx22 = matrixF[1][1];
	chx23 = matrixF[1][2];
	chx31 = matrixF[2][0];
	chx32 = matrixF[2][1];
	chx33 = matrixF[2][2];

	UpdateData(false);
}



// CbttView4

IMPLEMENT_DYNCREATE(CbttView4, CFormView)

BEGIN_MESSAGE_MAP(CbttView4, CFormView)
	ON_BN_CLICKED(IDC_BUTTON1, &CbttView4::OnBnClickedButtonSolve4)
END_MESSAGE_MAP()

// CbttView4 construction/destruction

CbttView4::CbttView4()
	: CFormView(CbttView4::IDD)
{
	// TODO: add construction code here

}

CbttView4::~CbttView4()
{
}

void CbttView4::DoDataExchange(CDataExchange* pDX)
{
	CView::DoDataExchange(pDX);
	DDX_Check(pDX, IDC_CHECK411, ch11);
	DDX_Check(pDX, IDC_CHECK412, ch12);
	DDX_Check(pDX, IDC_CHECK413, ch13);
	DDX_Check(pDX, IDC_CHECK414, ch14);
	DDX_Check(pDX, IDC_CHECK421, ch21);
	DDX_Check(pDX, IDC_CHECK422, ch22);
	DDX_Check(pDX, IDC_CHECK423, ch23);
	DDX_Check(pDX, IDC_CHECK424, ch24);
	DDX_Check(pDX, IDC_CHECK431, ch31);
	DDX_Check(pDX, IDC_CHECK432, ch32);
	DDX_Check(pDX, IDC_CHECK433, ch33);
	DDX_Check(pDX, IDC_CHECK434, ch34);
	DDX_Check(pDX, IDC_CHECK441, ch41);
	DDX_Check(pDX, IDC_CHECK442, ch42);
	DDX_Check(pDX, IDC_CHECK443, ch43);
	DDX_Check(pDX, IDC_CHECK444, ch44);
	DDX_Check(pDX, IDC_CHECK411s, chs11);
	DDX_Check(pDX, IDC_CHECK412s, chs12);
	DDX_Check(pDX, IDC_CHECK413s, chs13);
	DDX_Check(pDX, IDC_CHECK414s, chs14);
	DDX_Check(pDX, IDC_CHECK421s, chs21);
	DDX_Check(pDX, IDC_CHECK422s, chs22);
	DDX_Check(pDX, IDC_CHECK423s, chs23);
	DDX_Check(pDX, IDC_CHECK424s, chs24);
	DDX_Check(pDX, IDC_CHECK431s, chs31);
	DDX_Check(pDX, IDC_CHECK432s, chs32);
	DDX_Check(pDX, IDC_CHECK433s, chs33);
	DDX_Check(pDX, IDC_CHECK434s, chs34);
	DDX_Check(pDX, IDC_CHECK441s, chs41);
	DDX_Check(pDX, IDC_CHECK442s, chs42);
	DDX_Check(pDX, IDC_CHECK443s, chs43);
	DDX_Check(pDX, IDC_CHECK444s, chs44);
	DDX_Check(pDX, IDC_CHECK4112, chx11);
	DDX_Check(pDX, IDC_CHECK4122, chx12);
	DDX_Check(pDX, IDC_CHECK4132, chx13);
	DDX_Check(pDX, IDC_CHECK4142, chx14);
	DDX_Check(pDX, IDC_CHECK4212, chx21);
	DDX_Check(pDX, IDC_CHECK4222, chx22);
	DDX_Check(pDX, IDC_CHECK4232, chx23);
	DDX_Check(pDX, IDC_CHECK4242, chx24);
	DDX_Check(pDX, IDC_CHECK4312, chx31);
	DDX_Check(pDX, IDC_CHECK4322, chx32);
	DDX_Check(pDX, IDC_CHECK4332, chx33);
	DDX_Check(pDX, IDC_CHECK4342, chx34);
	DDX_Check(pDX, IDC_CHECK4412, chx41);
	DDX_Check(pDX, IDC_CHECK4422, chx42);
	DDX_Check(pDX, IDC_CHECK4432, chx43);
	DDX_Check(pDX, IDC_CHECK4442, chx44);
	DDX_Text(pDX, IDC_EDIT1, mess);
}

BOOL CbttView4::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

void CbttView4::OnInitialUpdate()
{
	CView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();

}


// CbttView4 diagnostics

#ifdef _DEBUG
void CbttView4::AssertValid() const
{
	CView::AssertValid();
}

void CbttView4::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CbttDoc* CbttView4::GetDocument() const // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CbttDoc)));
	return (CbttDoc*)m_pDocument;
}
#endif //_DEBUG


// CbttView4 message handlers

void CbttView4::OnBnClickedButtonSolve4()
{
	const int MAXsize = 4;
	int matrix[MAXsize][MAXsize] = {0};
	int matrixP[MAXsize][MAXsize] = {0};
	int matrixF[MAXsize][MAXsize] = {0};


	UpdateData(true);

	matrix[0][0] = ch11;
	matrix[0][1] = ch12;
	matrix[0][2] = ch13;
	matrix[0][3] = ch14;
	matrix[1][0] = ch21;
	matrix[1][1] = ch22;
	matrix[1][2] = ch23;
	matrix[1][3] = ch24;
	matrix[2][0] = ch31;
	matrix[2][1] = ch32;
	matrix[2][2] = ch33;
	matrix[2][3] = ch34;
	matrix[3][0] = ch41;
	matrix[3][1] = ch42;
	matrix[3][2] = ch43;
	matrix[3][3] = ch44;
	matrixP[0][0] = chs11;
	matrixP[0][1] = chs12;
	matrixP[0][2] = chs13;
	matrixP[0][3] = chs14;
	matrixP[1][0] = chs21;
	matrixP[1][1] = chs22;
	matrixP[1][2] = chs23;
	matrixP[1][3] = chs24;
	matrixP[2][0] = chs31;
	matrixP[2][1] = chs32;
	matrixP[2][2] = chs33;
	matrixP[2][3] = chs34;
	matrixP[3][0] = chs41;
	matrixP[3][1] = chs42;
	matrixP[3][2] = chs43;
	matrixP[3][3] = chs44;
	
	bool fail = true;
	int i,j,k,a,m,n,r;

	for(i = 0;(i<2) && fail;i++)
	{
		for(j = 0;(j<2) && fail;j++)
		{
			for(k = 0;(k<2) && fail;k++)
			{
				for( a = 0;(a<2) && fail;a++)
				{
					matrixF[0][0] = i;
					matrixF[0][1] = j;
					matrixF[0][2] = k;
					matrixF[0][3] = a;

					fail = false;

					for(m=1;m<MAXsize-1;m++)
					{
						for(n=0;n<MAXsize;n++)
						{
							r = 0;
							r += matrix[m-1][n];
							r += matrixF[m-1][n];
							if((m-2) >= 0)
								r += matrixF[m-2][n];
							if((n+1) < MAXsize)
								r += matrixF[m-1][n+1];
							if((n-1) >= 0)
								r += matrixF[m-1][n-1];

							if( (r%2) == matrixP[m-1][n])
								matrixF[m][n] = 0;
							else
								matrixF[m][n] = 1;
						}
					}
					
					for(n=0;n<MAXsize;n++)
					{
						r = 0;
						r += matrix[m-1][n];
						r += matrixF[m-1][n];
						if((m-2) >= 0)
							r += matrixF[m-2][n];
						if((n+1) < MAXsize)
							r += matrixF[m-1][n+1];
						if((n-1) >= 0)
							r += matrixF[m-1][n-1];

						if( (r%2) == matrixP[m-1][n])
							matrixF[m][n] = 0;
						else
							matrixF[m][n] = 1;
					
						
						if((n-1) >= 0)
						{
							r = 0;
							r += matrixF[m][n-1];
							r += matrixF[m-1][n-1];
							r += matrixF[m][n];
							r += matrix[m][n-1];
							if((n-2) >= 0)
							{
								r += matrixF[m][n-2];
							}
							if( (r%2) != matrixP[m][n-1])
								fail = true;
						}

						if(n == MAXsize-1)
						{
							r = 0;
							r += matrixF[m][n-1];
							r += matrixF[m-1][n];
							r += matrixF[m][n];
							r += matrix[m][n];
							if( (r%2) != matrixP[m][n])
								fail = true;
						}
						
					}
				}
			}
		}
	}

	chx11 = matrixF[0][0];
	chx12 = matrixF[0][1];
	chx13 = matrixF[0][2];
	chx14 = matrixF[0][3];
	chx21 = matrixF[1][0];
	chx22 = matrixF[1][1];
	chx23 = matrixF[1][2];
	chx24 = matrixF[1][3];
	chx31 = matrixF[2][0];
	chx32 = matrixF[2][1];
	chx33 = matrixF[2][2];
	chx34 = matrixF[2][3];
	chx41 = matrixF[3][0];
	chx42 = matrixF[3][1];
	chx43 = matrixF[3][2];
	chx44 = matrixF[3][3];
	if(fail)
		mess=_T("No solution");
	else
		mess=_T("");


	UpdateData(false);
}



// CbttView5

IMPLEMENT_DYNCREATE(CbttView5, CFormView)

BEGIN_MESSAGE_MAP(CbttView5, CFormView)
	ON_BN_CLICKED(IDC_BUTTON1, &CbttView5::OnBnClickedButtonSolve5)
END_MESSAGE_MAP()

// CbttView5 construction/destruction

CbttView5::CbttView5()
	: CFormView(CbttView5::IDD)
{
	// TODO: add construction code here

}

CbttView5::~CbttView5()
{
}

void CbttView5::DoDataExchange(CDataExchange* pDX)
{
	CView::DoDataExchange(pDX);
	DDX_Check(pDX, IDC_CHECK411, ch11);
	DDX_Check(pDX, IDC_CHECK412, ch12);
	DDX_Check(pDX, IDC_CHECK413, ch13);
	DDX_Check(pDX, IDC_CHECK414, ch14);
	DDX_Check(pDX, IDC_CHECK415, ch15);
	DDX_Check(pDX, IDC_CHECK421, ch21);
	DDX_Check(pDX, IDC_CHECK422, ch22);
	DDX_Check(pDX, IDC_CHECK423, ch23);
	DDX_Check(pDX, IDC_CHECK424, ch24);
	DDX_Check(pDX, IDC_CHECK425, ch25);
	DDX_Check(pDX, IDC_CHECK431, ch31);
	DDX_Check(pDX, IDC_CHECK432, ch32);
	DDX_Check(pDX, IDC_CHECK433, ch33);
	DDX_Check(pDX, IDC_CHECK434, ch34);
	DDX_Check(pDX, IDC_CHECK435, ch35);
	DDX_Check(pDX, IDC_CHECK441, ch41);
	DDX_Check(pDX, IDC_CHECK442, ch42);
	DDX_Check(pDX, IDC_CHECK443, ch43);
	DDX_Check(pDX, IDC_CHECK444, ch44);
	DDX_Check(pDX, IDC_CHECK445, ch45);
	DDX_Check(pDX, IDC_CHECK451, ch51);
	DDX_Check(pDX, IDC_CHECK452, ch52);
	DDX_Check(pDX, IDC_CHECK453, ch53);
	DDX_Check(pDX, IDC_CHECK454, ch54);
	DDX_Check(pDX, IDC_CHECK455, ch55);
	DDX_Check(pDX, IDC_CHECK411s, chs11);
	DDX_Check(pDX, IDC_CHECK412s, chs12);
	DDX_Check(pDX, IDC_CHECK413s, chs13);
	DDX_Check(pDX, IDC_CHECK414s, chs14);
	DDX_Check(pDX, IDC_CHECK415s, chs15);
	DDX_Check(pDX, IDC_CHECK421s, chs21);
	DDX_Check(pDX, IDC_CHECK422s, chs22);
	DDX_Check(pDX, IDC_CHECK423s, chs23);
	DDX_Check(pDX, IDC_CHECK424s, chs24);
	DDX_Check(pDX, IDC_CHECK425s, chs25);
	DDX_Check(pDX, IDC_CHECK431s, chs31);
	DDX_Check(pDX, IDC_CHECK432s, chs32);
	DDX_Check(pDX, IDC_CHECK433s, chs33);
	DDX_Check(pDX, IDC_CHECK434s, chs34);
	DDX_Check(pDX, IDC_CHECK435s, chs35);
	DDX_Check(pDX, IDC_CHECK441s, chs41);
	DDX_Check(pDX, IDC_CHECK442s, chs42);
	DDX_Check(pDX, IDC_CHECK443s, chs43);
	DDX_Check(pDX, IDC_CHECK444s, chs44);
	DDX_Check(pDX, IDC_CHECK445s, chs45);
	DDX_Check(pDX, IDC_CHECK451s, chs51);
	DDX_Check(pDX, IDC_CHECK452s, chs52);
	DDX_Check(pDX, IDC_CHECK453s, chs53);
	DDX_Check(pDX, IDC_CHECK454s, chs54);
	DDX_Check(pDX, IDC_CHECK455s, chs55);
	DDX_Check(pDX, IDC_CHECK4112, chx11);
	DDX_Check(pDX, IDC_CHECK4122, chx12);
	DDX_Check(pDX, IDC_CHECK4132, chx13);
	DDX_Check(pDX, IDC_CHECK4142, chx14);
	DDX_Check(pDX, IDC_CHECK4152, chx15);
	DDX_Check(pDX, IDC_CHECK4212, chx21);
	DDX_Check(pDX, IDC_CHECK4222, chx22);
	DDX_Check(pDX, IDC_CHECK4232, chx23);
	DDX_Check(pDX, IDC_CHECK4242, chx24);
	DDX_Check(pDX, IDC_CHECK4252, chx25);
	DDX_Check(pDX, IDC_CHECK4312, chx31);
	DDX_Check(pDX, IDC_CHECK4322, chx32);
	DDX_Check(pDX, IDC_CHECK4332, chx33);
	DDX_Check(pDX, IDC_CHECK4342, chx34);
	DDX_Check(pDX, IDC_CHECK4352, chx35);
	DDX_Check(pDX, IDC_CHECK4412, chx41);
	DDX_Check(pDX, IDC_CHECK4422, chx42);
	DDX_Check(pDX, IDC_CHECK4432, chx43);
	DDX_Check(pDX, IDC_CHECK4442, chx44);
	DDX_Check(pDX, IDC_CHECK4452, chx45);
	DDX_Check(pDX, IDC_CHECK4512, chx51);
	DDX_Check(pDX, IDC_CHECK4522, chx52);
	DDX_Check(pDX, IDC_CHECK4532, chx53);
	DDX_Check(pDX, IDC_CHECK4542, chx54);
	DDX_Check(pDX, IDC_CHECK4552, chx55);
	DDX_Text(pDX, IDC_EDIT2, mess);
}

BOOL CbttView5::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

void CbttView5::OnInitialUpdate()
{
	CView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();

}


// CbttView5 diagnostics

#ifdef _DEBUG
void CbttView5::AssertValid() const
{
	CView::AssertValid();
}

void CbttView5::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CbttDoc* CbttView5::GetDocument() const // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CbttDoc)));
	return (CbttDoc*)m_pDocument;
}
#endif //_DEBUG


// CbttView5 message handlers

void CbttView5::OnBnClickedButtonSolve5()
{
	const int MAXsize = 5;
	int matrix[MAXsize][MAXsize] = {0};
	int matrixP[MAXsize][MAXsize] = {0};
	int matrixF[MAXsize][MAXsize] ={0};


	UpdateData(true);

	matrix[0][0] = ch11;
	matrix[0][1] = ch12;
	matrix[0][2] = ch13;
	matrix[0][3] = ch14;
	matrix[0][4] = ch15;
	matrix[1][0] = ch21;
	matrix[1][1] = ch22;
	matrix[1][2] = ch23;
	matrix[1][3] = ch24;
	matrix[1][4] = ch25;
	matrix[2][0] = ch31;
	matrix[2][1] = ch32;
	matrix[2][2] = ch33;
	matrix[2][3] = ch34;
	matrix[2][4] = ch35;
	matrix[3][0] = ch41;
	matrix[3][1] = ch42;
	matrix[3][2] = ch43;
	matrix[3][3] = ch44;
	matrix[3][4] = ch45;
	matrix[4][0] = ch51;
	matrix[4][1] = ch52;
	matrix[4][2] = ch53;
	matrix[4][3] = ch54;
	matrix[4][4] = ch55;
	matrixP[0][0] = chs11;
	matrixP[0][1] = chs12;
	matrixP[0][2] = chs13;
	matrixP[0][3] = chs14;
	matrixP[0][4] = chs15;
	matrixP[1][0] = chs21;
	matrixP[1][1] = chs22;
	matrixP[1][2] = chs23;
	matrixP[1][3] = chs24;
	matrixP[1][4] = chs25;
	matrixP[2][0] = chs31;
	matrixP[2][1] = chs32;
	matrixP[2][2] = chs33;
	matrixP[2][3] = chs34;
	matrixP[2][4] = chs35;
	matrixP[3][0] = chs41;
	matrixP[3][1] = chs42;
	matrixP[3][2] = chs43;
	matrixP[3][3] = chs44;
	matrixP[3][4] = chs45;
	matrixP[4][0] = chs51;
	matrixP[4][1] = chs52;
	matrixP[4][2] = chs53;
	matrixP[4][3] = chs54;
	matrixP[4][4] = chs55;
	
	bool fail = true;
	int i,j,k,m,n,r,a,b;

	for( i = 0;i<2 && fail;i++)
	{
		for( j = 0;j<2 && fail;j++)
		{
			for( k = 0;k<2 && fail;k++)
			{
				for( a = 0;a<2 && fail;a++)
				{
					for( b = 0;b<2 && fail;b++)
					{
						fail = false;

						matrixF[0][0] = i;
						matrixF[0][1] = j;
						matrixF[0][2] = k;
						matrixF[0][3] = a;
						matrixF[0][4] = b;
						
						for(m=1;m<MAXsize-1;m++)
						{
							for(n=0;n<MAXsize;n++)
							{
								r = 0;
								r += matrix[m-1][n];
								r += matrixF[m-1][n];
								if((m-2) >= 0)
									r += matrixF[m-2][n];
								if((n+1) < MAXsize)
									r += matrixF[m-1][n+1];
								if((n-1) >= 0)
									r += matrixF[m-1][n-1];

								if( (r%2) == matrixP[m-1][n])
									matrixF[m][n] = 0;
								else
									matrixF[m][n] = 1;
							}
						}
					
						for(n=0;n<MAXsize;n++)
						{
							r = 0;
							r += matrix[m-1][n];
							r += matrixF[m-1][n];
							r += matrixF[m-2][n];
							if((n+1) < MAXsize)
								r += matrixF[m-1][n+1];
							if((n-1) >= 0)
								r += matrixF[m-1][n-1];

							if( (r%2) == matrixP[m-1][n])
								matrixF[m][n] = 0;
							else
								matrixF[m][n] = 1;
							
							
							if((n-1) >= 0)
							{
								r = 0;
								r += matrixF[m][n-1];
								r += matrixF[m-1][n-1];
								r += matrixF[m][n];
								r += matrix[m][n-1];
								if((n-2) >= 0)
								{
									r += matrixF[m][n-2];
								}
								if( (r%2) != matrixP[m][n-1])
									fail = true;
							}
							if(n == MAXsize-1)
							{
								r = 0;
								r += matrixF[m][n-1];
								r += matrixF[m-1][n];
								r += matrixF[m][n];
								r += matrix[m][n];
								if( (r%2) != matrixP[m][n])
									fail = true;
							}
						}
					}
				}
			}
		}
	}
	
	chx11 = matrixF[0][0];
	chx12 = matrixF[0][1];
	chx13 = matrixF[0][2];
	chx14 = matrixF[0][3];
	chx15 = matrixF[0][4];
	chx21 = matrixF[1][0];
	chx22 = matrixF[1][1];
	chx23 = matrixF[1][2];
	chx24 = matrixF[1][3];
	chx25 = matrixF[1][4];
	chx31 = matrixF[2][0];
	chx32 = matrixF[2][1];
	chx33 = matrixF[2][2];
	chx34 = matrixF[2][3];
	chx35 = matrixF[2][4];
	chx41 = matrixF[3][0];
	chx42 = matrixF[3][1];
	chx43 = matrixF[3][2];
	chx44 = matrixF[3][3];
	chx45 = matrixF[3][4];
	chx51 = matrixF[4][0];
	chx52 = matrixF[4][1];
	chx53 = matrixF[4][2];
	chx54 = matrixF[4][3];
	chx55 = matrixF[4][4];

	if(fail)
		mess=_T("No solution");
	else
		mess=_T("");


	UpdateData(false);
}




// CbttView6

IMPLEMENT_DYNCREATE(CbttView6, CFormView)

BEGIN_MESSAGE_MAP(CbttView6, CFormView)
	ON_BN_CLICKED(IDC_BUTTON1, &CbttView6::OnBnClickedButtonSolve6)
END_MESSAGE_MAP()

// CbttView6 construction/destruction

CbttView6::CbttView6()
	: CFormView(CbttView6::IDD)
{
	// TODO: add construction code here

}

CbttView6::~CbttView6()
{
}

void CbttView6::DoDataExchange(CDataExchange* pDX)
{
	CView::DoDataExchange(pDX);
	DDX_Check(pDX, IDC_CHECK411, ch11);
	DDX_Check(pDX, IDC_CHECK412, ch12);
	DDX_Check(pDX, IDC_CHECK413, ch13);
	DDX_Check(pDX, IDC_CHECK414, ch14);
	DDX_Check(pDX, IDC_CHECK415, ch15);
	DDX_Check(pDX, IDC_CHECK416, ch16);
	DDX_Check(pDX, IDC_CHECK421, ch21);
	DDX_Check(pDX, IDC_CHECK422, ch22);
	DDX_Check(pDX, IDC_CHECK423, ch23);
	DDX_Check(pDX, IDC_CHECK424, ch24);
	DDX_Check(pDX, IDC_CHECK425, ch25);
	DDX_Check(pDX, IDC_CHECK426, ch26);
	DDX_Check(pDX, IDC_CHECK431, ch31);
	DDX_Check(pDX, IDC_CHECK432, ch32);
	DDX_Check(pDX, IDC_CHECK433, ch33);
	DDX_Check(pDX, IDC_CHECK434, ch34);
	DDX_Check(pDX, IDC_CHECK435, ch35);
	DDX_Check(pDX, IDC_CHECK436, ch36);
	DDX_Check(pDX, IDC_CHECK441, ch41);
	DDX_Check(pDX, IDC_CHECK442, ch42);
	DDX_Check(pDX, IDC_CHECK443, ch43);
	DDX_Check(pDX, IDC_CHECK444, ch44);
	DDX_Check(pDX, IDC_CHECK445, ch45);
	DDX_Check(pDX, IDC_CHECK446, ch46);
	DDX_Check(pDX, IDC_CHECK451, ch51);
	DDX_Check(pDX, IDC_CHECK452, ch52);
	DDX_Check(pDX, IDC_CHECK453, ch53);
	DDX_Check(pDX, IDC_CHECK454, ch54);
	DDX_Check(pDX, IDC_CHECK455, ch55);
	DDX_Check(pDX, IDC_CHECK456, ch56);
	DDX_Check(pDX, IDC_CHECK461, ch61);
	DDX_Check(pDX, IDC_CHECK462, ch62);
	DDX_Check(pDX, IDC_CHECK463, ch63);
	DDX_Check(pDX, IDC_CHECK464, ch64);
	DDX_Check(pDX, IDC_CHECK465, ch65);
	DDX_Check(pDX, IDC_CHECK466, ch66);
	DDX_Check(pDX, IDC_CHECK411s, chs11);
	DDX_Check(pDX, IDC_CHECK412s, chs12);
	DDX_Check(pDX, IDC_CHECK413s, chs13);
	DDX_Check(pDX, IDC_CHECK414s, chs14);
	DDX_Check(pDX, IDC_CHECK415s, chs15);
	DDX_Check(pDX, IDC_CHECK416s, chs16);
	DDX_Check(pDX, IDC_CHECK421s, chs21);
	DDX_Check(pDX, IDC_CHECK422s, chs22);
	DDX_Check(pDX, IDC_CHECK423s, chs23);
	DDX_Check(pDX, IDC_CHECK424s, chs24);
	DDX_Check(pDX, IDC_CHECK425s, chs25);
	DDX_Check(pDX, IDC_CHECK426s, chs26);
	DDX_Check(pDX, IDC_CHECK431s, chs31);
	DDX_Check(pDX, IDC_CHECK432s, chs32);
	DDX_Check(pDX, IDC_CHECK433s, chs33);
	DDX_Check(pDX, IDC_CHECK434s, chs34);
	DDX_Check(pDX, IDC_CHECK435s, chs35);
	DDX_Check(pDX, IDC_CHECK436s, chs36);
	DDX_Check(pDX, IDC_CHECK441s, chs41);
	DDX_Check(pDX, IDC_CHECK442s, chs42);
	DDX_Check(pDX, IDC_CHECK443s, chs43);
	DDX_Check(pDX, IDC_CHECK444s, chs44);
	DDX_Check(pDX, IDC_CHECK445s, chs45);
	DDX_Check(pDX, IDC_CHECK446s, chs46);
	DDX_Check(pDX, IDC_CHECK451s, chs51);
	DDX_Check(pDX, IDC_CHECK452s, chs52);
	DDX_Check(pDX, IDC_CHECK453s, chs53);
	DDX_Check(pDX, IDC_CHECK454s, chs54);
	DDX_Check(pDX, IDC_CHECK455s, chs55);
	DDX_Check(pDX, IDC_CHECK456s, chs56);
	DDX_Check(pDX, IDC_CHECK461s, chs61);
	DDX_Check(pDX, IDC_CHECK462s, chs62);
	DDX_Check(pDX, IDC_CHECK463s, chs63);
	DDX_Check(pDX, IDC_CHECK464s, chs64);
	DDX_Check(pDX, IDC_CHECK465s, chs65);
	DDX_Check(pDX, IDC_CHECK466s, chs66);
	DDX_Check(pDX, IDC_CHECK4112, chx11);
	DDX_Check(pDX, IDC_CHECK4122, chx12);
	DDX_Check(pDX, IDC_CHECK4132, chx13);
	DDX_Check(pDX, IDC_CHECK4142, chx14);
	DDX_Check(pDX, IDC_CHECK4152, chx15);
	DDX_Check(pDX, IDC_CHECK4162, chx16);
	DDX_Check(pDX, IDC_CHECK4212, chx21);
	DDX_Check(pDX, IDC_CHECK4222, chx22);
	DDX_Check(pDX, IDC_CHECK4232, chx23);
	DDX_Check(pDX, IDC_CHECK4242, chx24);
	DDX_Check(pDX, IDC_CHECK4252, chx25);
	DDX_Check(pDX, IDC_CHECK4262, chx26);
	DDX_Check(pDX, IDC_CHECK4312, chx31);
	DDX_Check(pDX, IDC_CHECK4322, chx32);
	DDX_Check(pDX, IDC_CHECK4332, chx33);
	DDX_Check(pDX, IDC_CHECK4342, chx34);
	DDX_Check(pDX, IDC_CHECK4352, chx35);
	DDX_Check(pDX, IDC_CHECK4362, chx36);
	DDX_Check(pDX, IDC_CHECK4412, chx41);
	DDX_Check(pDX, IDC_CHECK4422, chx42);
	DDX_Check(pDX, IDC_CHECK4432, chx43);
	DDX_Check(pDX, IDC_CHECK4442, chx44);
	DDX_Check(pDX, IDC_CHECK4452, chx45);
	DDX_Check(pDX, IDC_CHECK4462, chx46);
	DDX_Check(pDX, IDC_CHECK4512, chx51);
	DDX_Check(pDX, IDC_CHECK4522, chx52);
	DDX_Check(pDX, IDC_CHECK4532, chx53);
	DDX_Check(pDX, IDC_CHECK4542, chx54);
	DDX_Check(pDX, IDC_CHECK4552, chx55);
	DDX_Check(pDX, IDC_CHECK4562, chx56);
	DDX_Check(pDX, IDC_CHECK4612, chx61);
	DDX_Check(pDX, IDC_CHECK4622, chx62);
	DDX_Check(pDX, IDC_CHECK4632, chx63);
	DDX_Check(pDX, IDC_CHECK4642, chx64);
	DDX_Check(pDX, IDC_CHECK4652, chx65);
	DDX_Check(pDX, IDC_CHECK4662, chx66);
	DDX_Text(pDX, IDC_EDIT2, mess);
}

BOOL CbttView6::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

void CbttView6::OnInitialUpdate()
{
	CView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();

}


// CbttView6 diagnostics

#ifdef _DEBUG
void CbttView6::AssertValid() const
{
	CView::AssertValid();
}

void CbttView6::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CbttDoc* CbttView6::GetDocument() const // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CbttDoc)));
	return (CbttDoc*)m_pDocument;
}
#endif //_DEBUG


// CbttView6 message handlers

void CbttView6::OnBnClickedButtonSolve6()
{
	const int MAXsize = 6;
	int matrix[MAXsize][MAXsize] = {0};
	int matrixP[MAXsize][MAXsize] = {0};
	int matrixF[MAXsize][MAXsize] ={0};


	UpdateData(true);

	matrix[0][0] = ch11;
	matrix[0][1] = ch12;
	matrix[0][2] = ch13;
	matrix[0][3] = ch14;
	matrix[0][4] = ch15;
	matrix[0][5] = ch16;
	matrix[1][0] = ch21;
	matrix[1][1] = ch22;
	matrix[1][2] = ch23;
	matrix[1][3] = ch24;
	matrix[1][4] = ch25;
	matrix[1][5] = ch26;
	matrix[2][0] = ch31;
	matrix[2][1] = ch32;
	matrix[2][2] = ch33;
	matrix[2][3] = ch34;
	matrix[2][4] = ch35;
	matrix[2][5] = ch36;
	matrix[3][0] = ch41;
	matrix[3][1] = ch42;
	matrix[3][2] = ch43;
	matrix[3][3] = ch44;
	matrix[3][4] = ch45;
	matrix[3][5] = ch46;
	matrix[4][0] = ch51;
	matrix[4][1] = ch52;
	matrix[4][2] = ch53;
	matrix[4][3] = ch54;
	matrix[4][4] = ch55;
	matrix[4][5] = ch56;
	matrix[5][0] = ch61;
	matrix[5][1] = ch62;
	matrix[5][2] = ch63;
	matrix[5][3] = ch64;
	matrix[5][4] = ch65;
	matrix[5][5] = ch66;
	matrixP[0][0] = chs11;
	matrixP[0][1] = chs12;
	matrixP[0][2] = chs13;
	matrixP[0][3] = chs14;
	matrixP[0][4] = chs15;
	matrixP[0][5] = chs16;
	matrixP[1][0] = chs21;
	matrixP[1][1] = chs22;
	matrixP[1][2] = chs23;
	matrixP[1][3] = chs24;
	matrixP[1][4] = chs25;
	matrixP[1][5] = chs26;
	matrixP[2][0] = chs31;
	matrixP[2][1] = chs32;
	matrixP[2][2] = chs33;
	matrixP[2][3] = chs34;
	matrixP[2][4] = chs35;
	matrixP[2][5] = chs36;
	matrixP[3][0] = chs41;
	matrixP[3][1] = chs42;
	matrixP[3][2] = chs43;
	matrixP[3][3] = chs44;
	matrixP[3][4] = chs45;
	matrixP[3][5] = chs46;
	matrixP[4][0] = chs51;
	matrixP[4][1] = chs52;
	matrixP[4][2] = chs53;
	matrixP[4][3] = chs54;
	matrixP[4][4] = chs55;
	matrixP[4][5] = chs56;
	matrixP[5][0] = chs61;
	matrixP[5][1] = chs62;
	matrixP[5][2] = chs63;
	matrixP[5][3] = chs64;
	matrixP[5][4] = chs65;
	matrixP[5][5] = chs66;
	bool fail = true;
	int i,j,k,m,n,r,a,b,c;

	for( i = 0;i<2 && fail;i++)
	{
		for( j = 0;j<2 && fail;j++)
		{
			for( k = 0;k<2 && fail;k++)
			{
				for( a = 0;a<2 && fail;a++)
				{
					for( b = 0;b<2 && fail;b++)
					{
						for( c = 0;c<2 && fail;c++)
						{
							fail = false;

							matrixF[0][0] = i;
							matrixF[0][1] = j;
							matrixF[0][2] = k;
							matrixF[0][3] = a;
							matrixF[0][4] = b;
							matrixF[0][5] = c;
							
							for(m=1;m<MAXsize-1;m++)
							{
								for(n=0;n<MAXsize;n++)
								{
									r = 0;
									r += matrix[m-1][n];
									r += matrixF[m-1][n];
									if((m-2) >= 0)
										r += matrixF[m-2][n];
									if((n+1) < MAXsize)
										r += matrixF[m-1][n+1];
									if((n-1) >= 0)
										r += matrixF[m-1][n-1];

									if( (r%2) == matrixP[m-1][n])
										matrixF[m][n] = 0;
									else
										matrixF[m][n] = 1;
								}
							}
						
							for(n=0;n<MAXsize;n++)
							{
								r = 0;
								r += matrix[m-1][n];
								r += matrixF[m-1][n];
								r += matrixF[m-2][n];
								if((n+1) < MAXsize)
									r += matrixF[m-1][n+1];
								if((n-1) >= 0)
									r += matrixF[m-1][n-1];

								if( (r%2) == matrixP[m-1][n])
									matrixF[m][n] = 0;
								else
									matrixF[m][n] = 1;
								
								
								if((n-1) >= 0)
								{
									r = 0;
									r += matrixF[m][n-1];
									r += matrixF[m-1][n-1];
									r += matrixF[m][n];
									r += matrix[m][n-1];
									if((n-2) >= 0)
									{
										r += matrixF[m][n-2];
									}
									if( (r%2) != matrixP[m][n-1])
										fail = true;
								}
								if(n == MAXsize-1)
								{
									r = 0;
									r += matrixF[m][n-1];
									r += matrixF[m-1][n];
									r += matrixF[m][n];
									r += matrix[m][n];
									if( (r%2) != matrixP[m][n])
										fail = true;
								}
							}
						}
					}
				}
			}
		}
	}
	
	chx11 = matrixF[0][0];
	chx12 = matrixF[0][1];
	chx13 = matrixF[0][2];
	chx14 = matrixF[0][3];
	chx15 = matrixF[0][4];
	chx16 = matrixF[0][5];
	chx21 = matrixF[1][0];
	chx22 = matrixF[1][1];
	chx23 = matrixF[1][2];
	chx24 = matrixF[1][3];
	chx25 = matrixF[1][4];
	chx26 = matrixF[1][5];
	chx31 = matrixF[2][0];
	chx32 = matrixF[2][1];
	chx33 = matrixF[2][2];
	chx34 = matrixF[2][3];
	chx35 = matrixF[2][4];
	chx36 = matrixF[2][5];
	chx41 = matrixF[3][0];
	chx42 = matrixF[3][1];
	chx43 = matrixF[3][2];
	chx44 = matrixF[3][3];
	chx45 = matrixF[3][4];
	chx46 = matrixF[3][5];
	chx51 = matrixF[4][0];
	chx52 = matrixF[4][1];
	chx53 = matrixF[4][2];
	chx54 = matrixF[4][3];
	chx55 = matrixF[4][4];
	chx56 = matrixF[4][5];
	chx61 = matrixF[5][0];
	chx62 = matrixF[5][1];
	chx63 = matrixF[5][2];
	chx64 = matrixF[5][3];
	chx65 = matrixF[5][4];
	chx66 = matrixF[5][5];

	if(fail)
		mess=_T("No solution");
	else
		mess=_T("");


	UpdateData(false);
}


// CbttView7

IMPLEMENT_DYNCREATE(CbttView7, CFormView)

BEGIN_MESSAGE_MAP(CbttView7, CFormView)
	ON_BN_CLICKED(IDC_BUTTON1, &CbttView7::OnBnClickedButtonSolve7)
END_MESSAGE_MAP()

// CbttView6 construction/destruction

CbttView7::CbttView7()
	: CFormView(CbttView7::IDD)
{
	// TODO: add construction code here

}

CbttView7::~CbttView7()
{
}

void CbttView7::DoDataExchange(CDataExchange* pDX)
{
	CView::DoDataExchange(pDX);
	DDX_Check(pDX, IDC_CHECK411, ch11);
	DDX_Check(pDX, IDC_CHECK412, ch12);
	DDX_Check(pDX, IDC_CHECK413, ch13);
	DDX_Check(pDX, IDC_CHECK414, ch14);
	DDX_Check(pDX, IDC_CHECK415, ch15);
	DDX_Check(pDX, IDC_CHECK416, ch16);
	DDX_Check(pDX, IDC_CHECK417, ch17);
	DDX_Check(pDX, IDC_CHECK421, ch21);
	DDX_Check(pDX, IDC_CHECK422, ch22);
	DDX_Check(pDX, IDC_CHECK423, ch23);
	DDX_Check(pDX, IDC_CHECK424, ch24);
	DDX_Check(pDX, IDC_CHECK425, ch25);
	DDX_Check(pDX, IDC_CHECK426, ch26);
	DDX_Check(pDX, IDC_CHECK427, ch27);
	DDX_Check(pDX, IDC_CHECK431, ch31);
	DDX_Check(pDX, IDC_CHECK432, ch32);
	DDX_Check(pDX, IDC_CHECK433, ch33);
	DDX_Check(pDX, IDC_CHECK434, ch34);
	DDX_Check(pDX, IDC_CHECK435, ch35);
	DDX_Check(pDX, IDC_CHECK436, ch36);
	DDX_Check(pDX, IDC_CHECK437, ch37);
	DDX_Check(pDX, IDC_CHECK441, ch41);
	DDX_Check(pDX, IDC_CHECK442, ch42);
	DDX_Check(pDX, IDC_CHECK443, ch43);
	DDX_Check(pDX, IDC_CHECK444, ch44);
	DDX_Check(pDX, IDC_CHECK445, ch45);
	DDX_Check(pDX, IDC_CHECK446, ch46);
	DDX_Check(pDX, IDC_CHECK447, ch47);
	DDX_Check(pDX, IDC_CHECK451, ch51);
	DDX_Check(pDX, IDC_CHECK452, ch52);
	DDX_Check(pDX, IDC_CHECK453, ch53);
	DDX_Check(pDX, IDC_CHECK454, ch54);
	DDX_Check(pDX, IDC_CHECK455, ch55);
	DDX_Check(pDX, IDC_CHECK456, ch56);
	DDX_Check(pDX, IDC_CHECK457, ch57);
	DDX_Check(pDX, IDC_CHECK461, ch61);
	DDX_Check(pDX, IDC_CHECK462, ch62);
	DDX_Check(pDX, IDC_CHECK463, ch63);
	DDX_Check(pDX, IDC_CHECK464, ch64);
	DDX_Check(pDX, IDC_CHECK465, ch65);
	DDX_Check(pDX, IDC_CHECK466, ch66);
	DDX_Check(pDX, IDC_CHECK467, ch67);
	DDX_Check(pDX, IDC_CHECK471, ch71);
	DDX_Check(pDX, IDC_CHECK472, ch72);
	DDX_Check(pDX, IDC_CHECK473, ch73);
	DDX_Check(pDX, IDC_CHECK474, ch74);
	DDX_Check(pDX, IDC_CHECK475, ch75);
	DDX_Check(pDX, IDC_CHECK476, ch76);
	DDX_Check(pDX, IDC_CHECK477, ch77);
	DDX_Check(pDX, IDC_CHECK411s, chs11);
	DDX_Check(pDX, IDC_CHECK412s, chs12);
	DDX_Check(pDX, IDC_CHECK413s, chs13);
	DDX_Check(pDX, IDC_CHECK414s, chs14);
	DDX_Check(pDX, IDC_CHECK415s, chs15);
	DDX_Check(pDX, IDC_CHECK416s, chs16);
	DDX_Check(pDX, IDC_CHECK417s, chs17);
	DDX_Check(pDX, IDC_CHECK421s, chs21);
	DDX_Check(pDX, IDC_CHECK422s, chs22);
	DDX_Check(pDX, IDC_CHECK423s, chs23);
	DDX_Check(pDX, IDC_CHECK424s, chs24);
	DDX_Check(pDX, IDC_CHECK425s, chs25);
	DDX_Check(pDX, IDC_CHECK426s, chs26);
	DDX_Check(pDX, IDC_CHECK427s, chs27);
	DDX_Check(pDX, IDC_CHECK431s, chs31);
	DDX_Check(pDX, IDC_CHECK432s, chs32);
	DDX_Check(pDX, IDC_CHECK433s, chs33);
	DDX_Check(pDX, IDC_CHECK434s, chs34);
	DDX_Check(pDX, IDC_CHECK435s, chs35);
	DDX_Check(pDX, IDC_CHECK436s, chs36);
	DDX_Check(pDX, IDC_CHECK437s, chs37);
	DDX_Check(pDX, IDC_CHECK441s, chs41);
	DDX_Check(pDX, IDC_CHECK442s, chs42);
	DDX_Check(pDX, IDC_CHECK443s, chs43);
	DDX_Check(pDX, IDC_CHECK444s, chs44);
	DDX_Check(pDX, IDC_CHECK445s, chs45);
	DDX_Check(pDX, IDC_CHECK446s, chs46);
	DDX_Check(pDX, IDC_CHECK447s, chs47);
	DDX_Check(pDX, IDC_CHECK451s, chs51);
	DDX_Check(pDX, IDC_CHECK452s, chs52);
	DDX_Check(pDX, IDC_CHECK453s, chs53);
	DDX_Check(pDX, IDC_CHECK454s, chs54);
	DDX_Check(pDX, IDC_CHECK455s, chs55);
	DDX_Check(pDX, IDC_CHECK456s, chs56);
	DDX_Check(pDX, IDC_CHECK457s, chs57);
	DDX_Check(pDX, IDC_CHECK461s, chs61);
	DDX_Check(pDX, IDC_CHECK462s, chs62);
	DDX_Check(pDX, IDC_CHECK463s, chs63);
	DDX_Check(pDX, IDC_CHECK464s, chs64);
	DDX_Check(pDX, IDC_CHECK465s, chs65);
	DDX_Check(pDX, IDC_CHECK466s, chs66);
	DDX_Check(pDX, IDC_CHECK467s, chs67);
	DDX_Check(pDX, IDC_CHECK471s, chs71);
	DDX_Check(pDX, IDC_CHECK472s, chs72);
	DDX_Check(pDX, IDC_CHECK473s, chs73);
	DDX_Check(pDX, IDC_CHECK474s, chs74);
	DDX_Check(pDX, IDC_CHECK475s, chs75);
	DDX_Check(pDX, IDC_CHECK476s, chs76);
	DDX_Check(pDX, IDC_CHECK477s, chs77);
	DDX_Check(pDX, IDC_CHECK4112, chx11);
	DDX_Check(pDX, IDC_CHECK4122, chx12);
	DDX_Check(pDX, IDC_CHECK4132, chx13);
	DDX_Check(pDX, IDC_CHECK4142, chx14);
	DDX_Check(pDX, IDC_CHECK4152, chx15);
	DDX_Check(pDX, IDC_CHECK4162, chx16);
	DDX_Check(pDX, IDC_CHECK4172, chx17);
	DDX_Check(pDX, IDC_CHECK4212, chx21);
	DDX_Check(pDX, IDC_CHECK4222, chx22);
	DDX_Check(pDX, IDC_CHECK4232, chx23);
	DDX_Check(pDX, IDC_CHECK4242, chx24);
	DDX_Check(pDX, IDC_CHECK4252, chx25);
	DDX_Check(pDX, IDC_CHECK4262, chx26);
	DDX_Check(pDX, IDC_CHECK4272, chx27);
	DDX_Check(pDX, IDC_CHECK4312, chx31);
	DDX_Check(pDX, IDC_CHECK4322, chx32);
	DDX_Check(pDX, IDC_CHECK4332, chx33);
	DDX_Check(pDX, IDC_CHECK4342, chx34);
	DDX_Check(pDX, IDC_CHECK4352, chx35);
	DDX_Check(pDX, IDC_CHECK4362, chx36);
	DDX_Check(pDX, IDC_CHECK4372, chx37);
	DDX_Check(pDX, IDC_CHECK4412, chx41);
	DDX_Check(pDX, IDC_CHECK4422, chx42);
	DDX_Check(pDX, IDC_CHECK4432, chx43);
	DDX_Check(pDX, IDC_CHECK4442, chx44);
	DDX_Check(pDX, IDC_CHECK4452, chx45);
	DDX_Check(pDX, IDC_CHECK4462, chx46);
	DDX_Check(pDX, IDC_CHECK4472, chx47);
	DDX_Check(pDX, IDC_CHECK4512, chx51);
	DDX_Check(pDX, IDC_CHECK4522, chx52);
	DDX_Check(pDX, IDC_CHECK4532, chx53);
	DDX_Check(pDX, IDC_CHECK4542, chx54);
	DDX_Check(pDX, IDC_CHECK4552, chx55);
	DDX_Check(pDX, IDC_CHECK4562, chx56);
	DDX_Check(pDX, IDC_CHECK4572, chx57);
	DDX_Check(pDX, IDC_CHECK4612, chx61);
	DDX_Check(pDX, IDC_CHECK4622, chx62);
	DDX_Check(pDX, IDC_CHECK4632, chx63);
	DDX_Check(pDX, IDC_CHECK4642, chx64);
	DDX_Check(pDX, IDC_CHECK4652, chx65);
	DDX_Check(pDX, IDC_CHECK4662, chx66);
	DDX_Check(pDX, IDC_CHECK4672, chx67);
	DDX_Check(pDX, IDC_CHECK4712, chx71);
	DDX_Check(pDX, IDC_CHECK4722, chx72);
	DDX_Check(pDX, IDC_CHECK4732, chx73);
	DDX_Check(pDX, IDC_CHECK4742, chx74);
	DDX_Check(pDX, IDC_CHECK4752, chx75);
	DDX_Check(pDX, IDC_CHECK4762, chx76);
	DDX_Check(pDX, IDC_CHECK4772, chx77);
	DDX_Text(pDX, IDC_EDIT2, mess);
}

BOOL CbttView7::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

void CbttView7::OnInitialUpdate()
{
	CView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();

}


// CbttView7 diagnostics

#ifdef _DEBUG
void CbttView7::AssertValid() const
{
	CView::AssertValid();
}

void CbttView7::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CbttDoc* CbttView7::GetDocument() const // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CbttDoc)));
	return (CbttDoc*)m_pDocument;
}
#endif //_DEBUG


// CbttView7 message handlers

void CbttView7::OnBnClickedButtonSolve7()
{
	const int MAXsize = 7;
	int matrix[MAXsize][MAXsize] = {0};
	int matrixP[MAXsize][MAXsize] = {0};
	int matrixF[MAXsize][MAXsize] ={0};


	UpdateData(true);

	matrix[0][0] = ch11;
	matrix[0][1] = ch12;
	matrix[0][2] = ch13;
	matrix[0][3] = ch14;
	matrix[0][4] = ch15;
	matrix[0][5] = ch16;
	matrix[0][6] = ch17;
	matrix[1][0] = ch21;
	matrix[1][1] = ch22;
	matrix[1][2] = ch23;
	matrix[1][3] = ch24;
	matrix[1][4] = ch25;
	matrix[1][5] = ch26;
	matrix[1][6] = ch27;
	matrix[2][0] = ch31;
	matrix[2][1] = ch32;
	matrix[2][2] = ch33;
	matrix[2][3] = ch34;
	matrix[2][4] = ch35;
	matrix[2][5] = ch36;
	matrix[2][6] = ch37;
	matrix[3][0] = ch41;
	matrix[3][1] = ch42;
	matrix[3][2] = ch43;
	matrix[3][3] = ch44;
	matrix[3][4] = ch45;
	matrix[3][5] = ch46;
	matrix[3][6] = ch47;
	matrix[4][0] = ch51;
	matrix[4][1] = ch52;
	matrix[4][2] = ch53;
	matrix[4][3] = ch54;
	matrix[4][4] = ch55;
	matrix[4][5] = ch56;
	matrix[4][6] = ch57;
	matrix[5][0] = ch61;
	matrix[5][1] = ch62;
	matrix[5][2] = ch63;
	matrix[5][3] = ch64;
	matrix[5][4] = ch65;
	matrix[5][5] = ch66;
	matrix[5][6] = ch67;
	matrix[6][0] = ch71;
	matrix[6][1] = ch72;
	matrix[6][2] = ch73;
	matrix[6][3] = ch74;
	matrix[6][4] = ch75;
	matrix[6][5] = ch76;
	matrix[6][6] = ch77;
	matrixP[0][0] = chs11;
	matrixP[0][1] = chs12;
	matrixP[0][2] = chs13;
	matrixP[0][3] = chs14;
	matrixP[0][4] = chs15;
	matrixP[0][5] = chs16;
	matrixP[0][6] = chs17;
	matrixP[1][0] = chs21;
	matrixP[1][1] = chs22;
	matrixP[1][2] = chs23;
	matrixP[1][3] = chs24;
	matrixP[1][4] = chs25;
	matrixP[1][5] = chs26;
	matrixP[1][6] = chs27;
	matrixP[2][0] = chs31;
	matrixP[2][1] = chs32;
	matrixP[2][2] = chs33;
	matrixP[2][3] = chs34;
	matrixP[2][4] = chs35;
	matrixP[2][5] = chs36;
	matrixP[2][6] = chs37;
	matrixP[3][0] = chs41;
	matrixP[3][1] = chs42;
	matrixP[3][2] = chs43;
	matrixP[3][3] = chs44;
	matrixP[3][4] = chs45;
	matrixP[3][5] = chs46;
	matrixP[3][6] = chs47;
	matrixP[4][0] = chs51;
	matrixP[4][1] = chs52;
	matrixP[4][2] = chs53;
	matrixP[4][3] = chs54;
	matrixP[4][4] = chs55;
	matrixP[4][5] = chs56;
	matrixP[4][6] = chs57;
	matrixP[5][0] = chs61;
	matrixP[5][1] = chs62;
	matrixP[5][2] = chs63;
	matrixP[5][3] = chs64;
	matrixP[5][4] = chs65;
	matrixP[5][5] = chs66;
	matrixP[5][6] = chs67;
	matrixP[6][0] = chs71;
	matrixP[6][1] = chs72;
	matrixP[6][2] = chs73;
	matrixP[6][3] = chs74;
	matrixP[6][4] = chs75;
	matrixP[6][5] = chs76;
	matrixP[6][6] = chs77;
	bool fail = true;
	int i,j,k,m,n,r,a,b,c,d;

	for( i = 0;i<2 && fail;i++)
	{
		for( j = 0;j<2 && fail;j++)
		{
			for( k = 0;k<2 && fail;k++)
			{
				for( a = 0;a<2 && fail;a++)
				{
					for( b = 0;b<2 && fail;b++)
					{
						for( c = 0;c<2 && fail;c++)
						{
							for( d = 0;d<2 && fail;d++)
							{
								fail = false;

								matrixF[0][0] = i;
								matrixF[0][1] = j;
								matrixF[0][2] = k;
								matrixF[0][3] = a;
								matrixF[0][4] = b;
								matrixF[0][5] = c;
								matrixF[0][6] = d;
								
								for(m=1;m<MAXsize-1;m++)
								{
									for(n=0;n<MAXsize;n++)
									{
										r = 0;
										r += matrix[m-1][n];
										r += matrixF[m-1][n];
										if((m-2) >= 0)
											r += matrixF[m-2][n];
										if((n+1) < MAXsize)
											r += matrixF[m-1][n+1];
										if((n-1) >= 0)
											r += matrixF[m-1][n-1];

										if( (r%2) == matrixP[m-1][n])
											matrixF[m][n] = 0;
										else
											matrixF[m][n] = 1;
									}
								}
							
								for(n=0;n<MAXsize;n++)
								{
									r = 0;
									r += matrix[m-1][n];
									r += matrixF[m-1][n];
									r += matrixF[m-2][n];
									if((n+1) < MAXsize)
										r += matrixF[m-1][n+1];
									if((n-1) >= 0)
										r += matrixF[m-1][n-1];

									if( (r%2) == matrixP[m-1][n])
										matrixF[m][n] = 0;
									else
										matrixF[m][n] = 1;
									
									
									if((n-1) >= 0)
									{
										r = 0;
										r += matrixF[m][n-1];
										r += matrixF[m-1][n-1];
										r += matrixF[m][n];
										r += matrix[m][n-1];
										if((n-2) >= 0)
										{
											r += matrixF[m][n-2];
										}
										if( (r%2) != matrixP[m][n-1])
											fail = true;
									}
									if(n == MAXsize-1)
									{
										r = 0;
										r += matrixF[m][n-1];
										r += matrixF[m-1][n];
										r += matrixF[m][n];
										r += matrix[m][n];
										if( (r%2) != matrixP[m][n])
											fail = true;
									}
								}
							}
						}
					}
				}
			}
		}
	}
	
	chx11 = matrixF[0][0];
	chx12 = matrixF[0][1];
	chx13 = matrixF[0][2];
	chx14 = matrixF[0][3];
	chx15 = matrixF[0][4];
	chx16 = matrixF[0][5];
	chx17 = matrixF[0][6];
	chx21 = matrixF[1][0];
	chx22 = matrixF[1][1];
	chx23 = matrixF[1][2];
	chx24 = matrixF[1][3];
	chx25 = matrixF[1][4];
	chx26 = matrixF[1][5];
	chx27 = matrixF[1][6];
	chx31 = matrixF[2][0];
	chx32 = matrixF[2][1];
	chx33 = matrixF[2][2];
	chx34 = matrixF[2][3];
	chx35 = matrixF[2][4];
	chx36 = matrixF[2][5];
	chx37 = matrixF[2][6];
	chx41 = matrixF[3][0];
	chx42 = matrixF[3][1];
	chx43 = matrixF[3][2];
	chx44 = matrixF[3][3];
	chx45 = matrixF[3][4];
	chx46 = matrixF[3][5];
	chx47 = matrixF[3][6];
	chx51 = matrixF[4][0];
	chx52 = matrixF[4][1];
	chx53 = matrixF[4][2];
	chx54 = matrixF[4][3];
	chx55 = matrixF[4][4];
	chx56 = matrixF[4][5];
	chx57 = matrixF[4][6];
	chx61 = matrixF[5][0];
	chx62 = matrixF[5][1];
	chx63 = matrixF[5][2];
	chx64 = matrixF[5][3];
	chx65 = matrixF[5][4];
	chx66 = matrixF[5][5];
	chx67 = matrixF[5][6];
	chx71 = matrixF[6][0];
	chx72 = matrixF[6][1];
	chx73 = matrixF[6][2];
	chx74 = matrixF[6][3];
	chx75 = matrixF[6][4];
	chx76 = matrixF[6][5];
	chx77 = matrixF[6][6];

	if(fail)
		mess=_T("No solution");
	else
		mess=_T("");


	UpdateData(false);
}
